﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PccCommonForC;
public partial class Manager_RSS_Rss : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["AdminUserID"] == null)
        {
            Response.Write("<script language=javascript>alert('Time is out.');window.open('../Default.aspx','_top');</script>");
            return;
        }
        if (!IsPostBack)
        {
            BindData();
        }
    }
    private void BindData()
    {
        PccMsg msg = new PccMsg();
        msg.CreateFirstNode("RssId", "0");
        msg.CreateFirstNode("Title", txtTenTheLoai.Text);
        msg.CreateFirstNode("Link", "");
        msg.CreateFirstNode("ShowMK", "");

        clsWebShop cls = new clsWebShop();
        DataSet ds = null;
        ds = cls.Get_RssByCondition(msg.GetXmlStr);
        grv_RSS.DataSource = ds;
        grv_RSS.DataBind();

    }

    protected void grv_RSS_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow )
        {
            Image imgSelectRSS = (Image)e.Row.FindControl("imgSelectRSS");
            if (DataBinder.Eval(e.Row.DataItem, "ShowMK").ToString() == "Y")
            {
                imgSelectRSS.ImageUrl = "~/Images/Icon/chooseIcon.gif";
            }
            else
            {
                imgSelectRSS.ImageUrl = "~/Images/Icon/cancel_icon.gif";
            }
        }
    }
    protected void btnAdd_Catalogue_Click(object sender, EventArgs e)
    {
        Response.Redirect("AddRss.aspx?CodeID=" + Request.QueryString["CodeID"]);
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BindData();
    }
    protected void grv_RSS_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        clsWebShop cls = new clsWebShop();
        cls.UpdateData("delete from Rss where RssId=" + grv_RSS.DataKeys[e.RowIndex].Value.ToString());
        ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('Dữ liệu đã cập nhật thành công')</script>");
        BindData();
    }
    
   
    protected void grv_RSS_RowCreated(object sender, GridViewRowEventArgs e)
    {
        for (int i = 0; i < grv_RSS.Rows.Count - 1; i++)
        {
            System.Web.UI.WebControls.WebControl myControl = grv_RSS.Rows[i].Cells[1];
            myControl.Attributes.Add("onclick", "if(confirm('Delete???')) return true; return false;");
        }
    }
}
